﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrightFrame;
using AIM.Model;
using System.Data;

namespace AIM.DAL
{
    public class RoleHasPurviewDAL
    {
        DbProvider dbProvider = new DbProvider();

        public List<string> QueryByRoleID(int roleID)
        {
            List<string> purviewList = new List<string>();
            using (IDataReader dr = dbProvider.ExecuteDataReader("SELECT PurviewID FROM role_has_purview WHERE RoleID=?RoleID",
                dbProvider.CreateParameter("?RoleID", DbType.Int32, roleID)))
            {
                while (dr.Read())
                {
                    purviewList.Add(dr["PurviewID"].ToString());
                }
            }
            return purviewList;
        }

        public void DeleteByRoleID(int roleID)
        {
            dbProvider.ExecuteNonQuery("DELETE FROM role_has_purview WHERE RoleID=?RoleID",
                dbProvider.CreateParameter("?RoleID", DbType.Int32, roleID));
        }

        public void Add(RoleHasPurview roleHasPurview)
        {
            dbProvider.ExecuteNonQuery("INSERT INTO role_has_purview (RoleID,PurviewID) VALUES (?RoleID,?PurviewID)",
                dbProvider.CreateParameter("?RoleID", DbType.Int32, roleHasPurview.Role.RoleID),
                dbProvider.CreateParameter("?PurviewID", DbType.AnsiString, roleHasPurview.Purview.PurviewID));
        }
    }
}
